public class SeqStack<T> : IStack<T>
{
    public int MaxSize { get; set; }//栈容量
    public T[] Data { get; set; }//数组，存储元素
    public int Top { get; set; }//指示栈顶
                                //索引器
    public T this[int index]
    {
        get
        {
            return Data[index];
        }
        set
        {
            Data[index] = value;
        }
    }

    /// <summary>
    /// 构造器  
    /// 初始化 InitStack(S)：构造一个空栈 S
    /// </summary>
    /// <param name="size"></param>
    public SeqStack(int size)
    {
        Data = new T[size];
        MaxSize = size;
        Top = -1;
    }

    public void Clear() => Top = -1;

    public int GetLength() => Top + 1;

    public T GetTop()
    {

        if (IsEmpty())
        {
            System.Console.WriteLine("空栈");
            return default(T);
        }
        return Data[Top];
    }
    /// <summary>
    /// 判空
    /// </summary>
    /// <returns></returns>
    public bool IsEmpty() => Top == -1;
    /// <summary>
    /// 出栈
    /// </summary>
    /// <returns></returns>
    public T Pop()
    {
        var temp = default(T);
        //判读是否会下溢
        if (IsEmpty())
        {
            System.Console.WriteLine("空栈");
            return temp;
        }
        temp = Data[Top];//注意必须在Top--之前赋值
        Top--;
        return temp;
    }
    /// <summary>
    /// 进栈
    /// </summary>
    /// <param name="item"></param>
    public void Push(T item)
    {
        //判断是否会上溢
        if (IsFull())
        {
            System.Console.WriteLine("栈满");
            return;
        }
        //这里注意下++Top已经把Top标识进行+1操作了
        Data[++Top] = item;
    }

    //判断顺序栈是否为满
    public bool IsFull() => Top == (MaxSize - 1);

}